package co.edu.javeriana.aes.patrones.monopolio.cliente;

import co.edu.javeriana.aes.patrones.monopolio.message.Message;
import co.edu.javeriana.aes.patrones.monopolio.message.MessageType;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author gersua
 */
public class LoginJPanel extends AbstractPanel {

    private Image bgImage;

    /** Creates new form LoginJPanel */
    public LoginJPanel(MonopolyClient client, ViewHandler viewHandler) {
        super(client, viewHandler);
        initComponents();
        bgImage = new ImageIcon(getClass().getResource("/co/edu/javeriana"
                    + "/aes/patrones/monopolio/cliente/resources/monopoly-global-bg-sm.jpg")).getImage();
        setSize(1366, 650);
        btnLogIn.addActionListener(viewHandler);
    }

    @Override
    public void paintComponent(Graphics g) {
        g.drawImage(bgImage, 0, 0, null);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtLogIn = new javax.swing.JTextField();
        btnLogIn = new javax.swing.JButton();

        setBackground(new java.awt.Color(0, 0, 0));
        setPreferredSize(new java.awt.Dimension(1366, 650));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/javeriana/aes/patrones/monopolio/cliente/resources/monopoly_us_pack_logo.png"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 24));
        jLabel2.setText("Ingresa tu Nick:");

        txtLogIn.setFont(new java.awt.Font("Lucida Grande", 0, 24));

        btnLogIn.setFont(new java.awt.Font("Lucida Grande", 0, 18));
        btnLogIn.setText("Ingresar!");
        btnLogIn.setName("btnLogIn"); // NOI18N
        btnLogIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogInActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtLogIn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 402, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(btnLogIn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(337, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel2)
                        .add(txtLogIn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(btnLogIn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(125, 125, 125))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnLogInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogInActionPerformed

        Message message = new Message(null, txtLogIn.getText(), MessageType.F_SESSION_REQUEST);
        getMonopolyClient().sendMessage(message);
    }//GEN-LAST:event_btnLogInActionPerformed

    public JButton getBtnLogIn() {
        return btnLogIn;
    }

    public JTextField getTxtLogIn() {
        return txtLogIn;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLogIn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtLogIn;
    // End of variables declaration//GEN-END:variables
}
